package com.leyou.common.advice;

import com.leyou.common.exception.ExceptionResult;
import com.leyou.common.exception.LyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice  //默认情况下会拦截所有的controller类
public class BasicExceptionAdvice {

    /*返回值为自定义的异常处理结果*/
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleException(LyException e){
        return  ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e) );
    }
}
